package test;

import org.junit.Test;

import java.util.ArrayList;

import java.util.Collections;

//寻找第K大
public class topic09 {
    @Test
    public void test01(){
        System.out.println(findKth(new int[]{2, 3, 4, 1, 7},5,3));
    }
    public int findKth(int[] a, int n, int K) {
        ArrayList <Integer> l = new ArrayList ();
        for (int i = 0; i < a.length; i++) {
            l.add(a[i]);
        }

        Collections.sort(l);
        int index = l.size() -1 ;
        while(K>1){
            int temp = l.get(index);
            index--;
            while(l.get(index) == temp){
                index--;
            }K--;
        }
        return l.get(index);
    }
}

